package cn.boy.web.controller;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.boy.domain.Adminstrator;
import cn.boy.domain.Student;
import cn.boy.service.AdminstratorService;
import cn.boy.service.AdminstratorServiceFactory;
import cn.boy.service.DormitoryServiceFactory;
import cn.boy.service.StudentService;
import cn.boy.service.StudentServiceFactory;
import cn.boy.utils.Util;

import com.sun.org.apache.commons.beanutils.BeanUtils;

public class StudentUpdateServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		response.setContentType("text/html;charset=UTF-8");
		Map map = request.getParameterMap();
		try {
			if (!Util.isEmpty(map)) {
				Student student = new Student();
				BeanUtils.populate(student, map);
				student.setNO(request.getParameter("no"));
				student.setName(new String(request.getParameter("name").getBytes("ISO-8859-1"), "UTF-8"));
				System.out.println("student --->>" + student);
				StudentServiceFactory instance = StudentServiceFactory.getInstance();
				StudentService service = instance.getStudentService();
				service.updateStudent(student);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}

	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
